//获取应用实例
var app = getApp();
Page({
	data: {
		inputShowed:false,
		inputVal:"",
		buildingtext:"楼栋",
		floortext:"楼层",
		formattext:"业态",
		building:['1D', '2D', '3D', '4D', '5D', '6D', '7D', '8D', '9D', '10D', '11D', '12D', 'B栋', '全部'],
		floor:['-1F', '1F', '2F', '3F', '4F', '5F', '6F', '全部'],
		format:[],
		imgpath:app.setting.apiimgpath,
		typeSellerData:{},
		isData:true,
	},
	onLoad(){
		var that    = this;
		var _farmat = [];
		app.request('/api/Seller/getTypeSeller', {}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data
				});
			}
		});
		app.request('/api/Seller/getOperation', {}, function(res){
			if(res.code == '0'){
				//更新数据
				for(var i = 0; i < res.data.length; i++){
					_farmat.push(res.data[i].name);
				}
				that.setData({
					format: _farmat
				})
			}
		});
	},
	showInput:function(){
		this.setData({
			inputShowed:true
		});
	},
	hideInput:function(){
		var that = this;
		var param = {};
		if(this.data.inputVal){
			param.title = this.data.inputVal;
		}
		app.request('/api/Seller/getTypeSeller', param, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data
				});
			}
		});
	},
	clearInput:function(){
		this.setData({
			inputVal:""
		});
	},
	inputTyping: function(e) {
		this.setData({
			inputVal: e.detail.value
		});
	},
	//楼栋
	bindBuilding: function(e){
		var that = this;
		this.setData({
			buildingtext:this.data.building[e.detail.value]
		})
		if(that.data.floortext=='楼层' || that.data.floortext=='全部'){
			var _floortext = '';
		}
		else{
			var _floortext = that.data.floortext;
		}
		if(that.data.formattext == '业态'){
			var _formattext = '';
		}
		else{
			if(that.data.formattext == '美食'){
				var _formattext = 1;
			}
			else if(that.data.formattext == '购物'){
				var _formattext = 2;
			}
			else if(that.data.formattext == '亲子'){
				var _formattext = 3;
			}
			else if(that.data.formattext == '娱乐'){
				var _formattext = 4;
			}
			else if(that.data.formattext == '文创'){
				var _formattext = 5;
			}
		}
		var param = {layer:_floortext, operation_id:_formattext};
		if(this.data.building[e.detail.value] == "全部"){
			param.tung = '';
		}
		else{
			param.tung = that.data.building[e.detail.value];
		}
		app.request('/api/Seller/getTypeSeller', param, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data
				})
				if(res.data.length == 0){
					that.setData({
						isData:false
					})
				}else{
					that.setData({
						isData:true
					})
				}
			}
		});
	},
	//楼层
	bindFloor:function(e){
		var that = this;
		this.setData({
			floortext:this.data.floor[e.detail.value]
		})
		if(that.data.buildingtext=='楼栋' || that.data.buildingtext=='全部'){
			var _buildingtext = '';
		}
		else{
			var _buildingtext = that.data.buildingtext;
		}
		if(that.data.formattext == '业态'){
			var _formattext = '';
		}
		else{
			if(that.data.formattext == '美食'){
				var _formattext = 1;
			}
			else if(that.data.formattext == '购物'){
				var _formattext = 2;
			}
			else if(that.data.formattext == '亲子'){
				var _formattext = 3;
			}
			else if(that.data.formattext == '娱乐'){
				var _formattext = 4;
			}
			else if(that.data.formattext == '文创'){
				var _formattext = 5;
			}
		}
		var param = {tung:_buildingtext, operation_id:_formattext};
		if(this.data.floor[e.detail.value] == "全部"){
			param.layer = '';
		}
		else{
			param.layer = that.data.floor[e.detail.value];
		}
		app.request('/api/Seller/getTypeSeller', param, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data
				})
				if(res.data.length == 0){
					that.setData({
						isData:false
					})
				}else{
					that.setData({
						isData:true
					})
				}
			}
		});
	},
	//业态
	bindFormat: function(e){
		var that = this;
		this.setData({
			formattext:this.data.format[e.detail.value]
		})
		if(that.data.buildingtext=='楼栋' || that.data.buildingtext=='全部'){
			var _buildingtext = '';
		}
		else{
			var _buildingtext = that.data.buildingtext;
		}
		if(that.data.floortext=='楼层' || that.data.floortext=='全部') {
			var _floortext = '';
		}
		else{
			var _floortext = that.data.floortext;
		}
		if(this.data.format[e.detail.value] == '美食'){
			var _format = 1;
		}
		else if(that.data.format[e.detail.value] == '购物'){
			var _format = 2;
		}
		else if(that.data.format[e.detail.value] == '亲子'){
			var _format = 3;
		}
		else if(that.data.format[e.detail.value] == '娱乐'){
			var _format = 4;
		}
		else if(that.data.format[e.detail.value] == '文创'){
			var _format = 5;
		}
		var param = {tung:_buildingtext, layer:_floortext};
		if(this.data.format[e.detail.value] == "全部"){
			param.operation_id = '';
		}
		else{
			param.operation_id = _format;
		}
		app.request('/api/Seller/getTypeSeller', param, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data
				})
				if(res.data.length == 0){
					that.setData({
						isData:false
					})
				}else{
					that.setData({
						isData:true
					})
				}
			}
		});
	},
	backData:function(){
		var that = this;
		app.request('/api/Seller/getTypeSeller', {}, function(res){
			if(res.code == '0'){
				//更新数据
				that.setData({
					typeSellerData:res.data,
					buildingtext: "楼栋",
					floortext:"楼层",
					formattext:"业态"
				})
				if(res.data.length == 0){
					that.setData({
						isData:false
					})
				}else{
					that.setData({
						isData:true
					})
				}
			}
		});
	}
});